﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Catering.View_Operaction;
using System.Data;
using Microsoft.Reporting.WebForms;

namespace Catering.Catering_Page.ShanShiFenXi
{
    public partial class OilPersonContrast : System.Web.UI.Page
    {
        private static View_Monitor vm = new View_Monitor();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DateTime tempDate = DateTime.Now;
                if (Session["OilPersonYear"] != null)
                {
                    DateTime.TryParse(Session["OilPersonYear"].ToString() + "-01-01 00:00:11", out tempDate);
                }
                if (!string.IsNullOrEmpty(Request.QueryString["GroupID"]))
                {
                    BingCharDataSouce(Request.QueryString["GroupID"], "-10", tempDate);
                }
                else if (!string.IsNullOrEmpty(Request.QueryString["ClassID"]))
                {
                    BingCharDataSouce("-10", Request.QueryString["ClassID"], tempDate);
                }
                else if (!string.IsNullOrEmpty(Request.QueryString["tuxingtongji"]))
                {
                    string tuxingtongji = Request.QueryString["tuxingtongji"];
                    if (tuxingtongji.Equals("sdfdswe22342sgd4w342"))
                    {
                        if (Session["OilCLASSID"] != null && Session["OilAREAID"] != null)
                        {
                            BingCharDataSouce(Session["OilAREAID"].ToString(), Session["OilCLASSID"].ToString(), tempDate);
                        }
                    }
                }
            }
        }

        private void BingCharDataSouce(string AREAID, string CLASSID, DateTime DTIME)
        {

            string Title = Bind_Data_to_Controls.Bind_ReportTitle(AREAID, CLASSID, DTIME, "食用油人均消耗值");
            string pid = "0";
            if (Session["UserID"] != null) pid = Session["UserID"].ToString();
            DataTable dt = vm.GetOilPersonAvgForChar(pid, AREAID, CLASSID, DTIME, Title);
           
            ReportDataSource rds = new ReportDataSource("DataSet1", dt);
            ReportViewer2.LocalReport.DataSources.Clear();
            ReportViewer2.LocalReport.DataSources.Add(rds);
            ReportViewer2.LocalReport.Refresh();
            ReportViewer2.Visible = true;
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", @"<script>divshow('div_bg','div_main');</script>");
            lbtnTyleChar_Click(new object(), null);
        }

        protected void lbtnTyleChar_Click(object sender, EventArgs e)
        {
            string AREAID = DDLTool1.GetDDL_Area();
            string CLASSID = DDLTool1.GetDDL_Class();
            string YEAR = DDLTool1.GetYear();
            if (string.IsNullOrEmpty(AREAID) || string.IsNullOrEmpty(CLASSID) || string.IsNullOrEmpty(YEAR))
            {
                if (Session["OilCLASSID"] != null && Session["OilAREAID"] != null && Session["OilPersonYear"] != null)
                {
                    CLASSID = Session["OilCLASSID"].ToString();
                    AREAID = Session["OilAREAID"].ToString();
                    YEAR = Session["OilPersonYear"].ToString();
                }
            }
            else
            {
                Session["OilCLASSID"] = CLASSID;
                Session["OilAREAID"] = AREAID;
                Session["OilPersonYear"] = YEAR;
            }
            if (string.IsNullOrEmpty(YEAR))
            {
                return;
            }
            DateTime DTIME = DateTime.Parse(YEAR + "-01-01 00:00:11");
            string Title = Bind_Data_to_Controls.Bind_ReportTitle(AREAID, CLASSID, DTIME, "食用油人均消耗值");
            string pid = "0";
            if (Session["UserID"] != null) pid = Session["UserID"].ToString();
            DataTable dt = vm.GetOilPersonAvgContrant(pid,AREAID, CLASSID, DTIME, Title);
            ReportDataSource rds = new ReportDataSource("DataSet1", dt);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(rds);
            ReportViewer1.LocalReport.Refresh();
            ReportViewer1.Visible = true;
        }
    }
}